﻿using System;
using System.Windows.Forms;
using DataLayer;

namespace WinProgProject2
{
    public partial class AnaForm : Form
    {
        enum Mod { Genel, Diyalog };
        public AnaForm()
        {
            InitializeComponent();
        }

        private void kullaniciIslemleriMenuItem_Click(object sender, EventArgs e)
        {
            
            formGoster(new KullaniciIslemleri(),(int)Mod.Genel);

        }

        private void formKapat()
        {
            foreach (Control c in pnlAna.Controls)
                if (c is Form)
                {
                    ((Form)c).Close();
                    ((Form)c).Dispose();
                    pnlAna.Controls.Clear();
                }
        }

        private void musteriOnceligiMenuItem_Click(object sender, EventArgs e)
        {
            formGoster(new OncelikIslemleri(), (int)Mod.Diyalog);

        }

        private void musteriYonetimiMenuItem_Click(object sender, EventArgs e)
        {
            formGoster(new MusteriIslemleri(), (int)Mod.Genel);
            
        }

        private void masaYonetimiMenuItem_Click(object sender, EventArgs e)
        {
            formGoster(new MasaIslemleri(), (int)Mod.Genel);
        }
        private void formGoster(Form frm, int mod)
        {
            if (mod == (int)Mod.Genel)
            {
                formKapat();
                frm.TopLevel = false;
                frm.Top = 0;
                frm.Dock = DockStyle.Fill;
                frm.Visible = true;
                pnlAna.Controls.Add(frm);
            }
            else
            {
                frm.StartPosition = FormStartPosition.CenterParent;
                frm.ShowDialog(this);
            }
        }

        private void rezervasyonIslemleriMenuItem_Click(object sender, EventArgs e)
        {
            formGoster(new RezervasyonIslemleri(), (int)Mod.Genel);
        }

        private void notifyIcon_DoubleClick(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
            this.ShowInTaskbar = true;
        }

        private void AnaForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!Program.loginCancel)
            {
                e.Cancel = true;

                this.WindowState = FormWindowState.Minimized;
                this.ShowInTaskbar = false;
                notifyIcon.ShowBalloonTip(500);
            }
        }

        private void cikisMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void AnaForm_Load(object sender, EventArgs e)
        {
            formGoster(new Login(),(int)Mod.Diyalog);
            formGoster(new Giris(),(int)Mod.Genel);

            for (int i = 0; i < Session.yetkiler.Count; i++)
                anaMenuStrip.Items[i].Visible = Convert.ToBoolean(Session.yetkiler[i]);
        }


        private void masaTipiYönetimiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            formGoster(new MasaTipiIslemleri(), (int)Mod.Diyalog);
        }

        private void raporGoruntulemeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            formGoster(new RaporGoruntuleme(),(int)Mod.Diyalog);
        }

        private void cikisToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.loginCancel = true;
            Application.Exit();
        }

        private void islemLoguGörüntülemeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            formGoster(new LogGoruntuleme(),(int)Mod.Diyalog);
        }
        


        


    }
}
